import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'
// import Home from '../components/Home.vue'
// import Welcome from '../components/Welcome.vue'
// import Users from '../components/user/Users.vue'
// import Roles from '../components/power/Roles.vue'
// import Rights from '../components/power/Rights.vue'
// import Categories from '../components/goods/Categories.vue'
// import Params from '../components/goods/Params.vue'
// import Goods from '../components/goods/Goods.vue'
// import GoodsAdd from '../components/goods/Add.vue'
// import Orders from '../components/order/Orders.vue'
// import Reports from '../components/report/Reports.vue'
Vue.use(VueRouter)
// const router = new VueRouter({
//   routes: [
//     { path: '/', redirect: '/login' },
//     { path: '/login', component: Login },
//     {
//       path: '/home',
//       component: Home,
//       redirect: '/welcome',
//       children: [
//         { path: '/welcome', component: Welcome },
//         { path: '/users', component: Users },
//         { path: '/roles', component: Roles },
//         { path: '/rights', component: Rights },
//         { path: '/categories', component: Categories },
//         { path: '/params', component: Params },
//         { path: '/goods', component: Goods },
//         { path: '/goods/add', component: GoodsAdd },
//         { path: '/orders', component: Orders },
//         { path: '/reports', component: Reports }
//       ]
//     }
//   ]
// })
const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: () => import(/* webpackChunkName: "home" */ '../components/Login.vue') },
    {
      path: '/home',
      component: () => import(/* webpackChunkName: "home" */ '../components/Home.vue'),
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: () => import(/* webpackChunkName: "home" */ '../components/Welcome.vue') },
        { path: '/users', component: () => import(/* webpackChunkName: "users" */ '../components/user/Users.vue') },
        { path: '/roles', component: () => import(/* webpackChunkName: "roles" */ '../components/power/Roles.vue') },
        { path: '/rights', component: () => import(/* webpackChunkName: "rights" */ '../components/power/Rights.vue') },
        { path: '/categories', component: () => import(/* webpackChunkName: "cate" */ '../components/goods/Categories.vue') },
        { path: '/params', component: () => import(/* webpackChunkName: "params" */ '../components/goods/Params.vue') },
        { path: '/goods', component: () => import(/* webpackChunkName: "goods" */ '../components/goods/Goods.vue') },
        { path: '/goods/add', component: () => import(/* webpackChunkName: "add" */ '../components/goods/Add.vue') },
        { path: '/orders', component: () => import(/* webpackChunkName: "orders" */ '../components/order/Orders.vue') },
        { path: '/reports', component: () => import(/* webpackChunkName: "reports" */ '../components/report/Reports.vue') }
      ]
    }
  ]
})

// from shanghai to hangzhou
router.beforeEach((to, from, next) => {
  // 如果你想买票，直接放行
  if (to.path === '/login') return next()
  // 如果你想看电影，先把你的票拿出来看一下，如果没有票，就让你去买票，如果有，就放行
  var tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})
export default router
